// import './indexSass.scss';
import React, { useEffect } from 'react';
import ReactDOM from 'react-dom';
// import './page1.scss';
import { request } from '../util/wpsHttp';

const WebOfficeSDK = require('../util/web-office-sdk-v1.1.5.es');
let WPS: any = null;
const App = () => {
  useEffect(() => {
    start();
  }, []);
  const start = async function () {
    WPS = WebOfficeSDK.config({
      mout: document.getElementById('wps'),
      // url: "https://wwo.wps.cn/office/w/93324863331?_w_appid=e9d66a1b98494efb977bec12f8821a84&_w_signature=tBnhFqvVrC1LcJKye1m7GjzvqoA"
      // url: "https://www.kdocs.cn/p/93324863331?from=docs&source=docsWeb"
      url: 'https://wwo.wps.cn/office/w/12333?_w_type=original&_w_fileid=12333&_w_appid=e9d66a1b98494efb977bec12f8821a84&_w_signature=b%2BX3Jj39xiWgrnGHw6FeJopTO0I%3D',
    });
    WPS.setCommandBars([
      // 可以配置多个组件控制显示和隐藏
      {
        cmbId: 'HeaderLeft',
        attributes: [
          {
            name: 'visible',
            value: false,
          },
          {
            name: 'enable',
            value: false,
          },
        ],
      },
      {
        cmbId: 'HeaderRight',
        attributes: [
          {
            name: 'visible',
            value: false,
          },
          {
            name: 'enable',
            value: false,
          },
        ],
      },
    ]);
    WPS?.on('fileOpen', async (data: any) => {});
    // WPS.setToken({ token: "98fa095f3aba4b07b1fe337c52dfa1de" }); // 替换成自己的token
    // WPS.setToken({ token: "760cf5a6df739ac8d74d7421a04c8597" }); // 替换成自己的token
    await WPS.ready();
    console.log('ready', 23456789);
    const pdfUrl =
      await WPS.WordApplication().ActiveDocument.ExportAsFixedFormat();
    console.log(pdfUrl);
  };
  return (
    <div>
      <div id="wps"></div>
      <button
        onClick={async () => {
          console.log(WPS);
          const pdfUrl =
            await WPS.WordApplication().ActiveDocument.ExportAsFixedFormat();
          console.log(pdfUrl);
          // request('get', 'http://fytest.onecc.net/v1/3rd/file/info?_w_appid=e9d66a1b98494efb977bec12f8821a84&_w_param1=1000&_w_param2=11.18速记1.6需求会议.doc&_w_signature=tBnhFqvVrC1LcJKye1m7GjzvqoA%3D')
        }}
      >
        保存文件
      </button>
    </div>
  );
};

ReactDOM.render(<App />, document.getElementById('root1'));
